﻿using CPPEI.Coolzon.Common;
using CPPEI.Coolzon.Configuration.Client;
using CPPEI.Coolzon.UI;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Navigation;

namespace CPPEI.Coolzon.BrowserApp
{ 
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            Logger.InitByLogDirectory(CZEnvironment.GetLogDirectory());
            Logger.DebugToTag("UI", "程序启动!");

            string paramString = StartupUtil.GetStartupParamString();
            Logger.DebugToTag("UI", "启动参数:{0}", paramString);
            StartupUtil.ParseParamString(paramString);

            // 初始化主服务器的配置信息
            CPPEI.Coolzon.Configuration.Client.Config.InitHostConfig(CZEnvironment.GetHostConfigFilePath());
            // 初始化备用服务器的配置信息
            //CPPEI.Coolzon.Configuration.Client.Config.InitSpareHostConfig(CZEnvironment.GetSpareHostConfigFilePath());

            CPPEI.Coolzon.Configuration.Client.Config.InitPartLibsConfig(CZEnvironment.GetPartLibConfigFilePath());
            Config.PartLibs.PartLibsBaseAddress = CZEnvironment.GetPartLibBaseAddress();

            // 初始化所有的客户端代理实例
            ServiceProxy.ClientProxyManager.Instance.InitClientProxyList(RemoteEventProxy.Instance);

            RemoteEventProxy.Instance.SetMainServiceClient(ServiceProxy.ProxyFactory.InitMainServiceClient(RemoteEventProxy.Instance));

            UIContext.Current.AppStartupPath = AppDomain.CurrentDomain.BaseDirectory;
            UIContext.Current.AppType = "BrowseApp";
            UIContext.Current.AppVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
            UIContext.Current.OSVersion = System.Environment.OSVersion.Version.ToString();
            UIContext.Current.DotNetVersion = System.Environment.Version.ToString();
            UIContext.Current.IsUnderControl = false;

            CPPEI.Coolzon.UI.Task.DataResultCache.Init(string.Format("{0}\\Coolzon\\BroswerApp\\Cache\\Data\\",
                Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)));

            this.StartupUri = new Uri(".\\MainPage.xaml", UriKind.Relative);
            base.OnStartup(e);
        }
    }
}
